# /usr/bin/python3
# -*- coding: utf-8 -*-
# @Time    : 2022/1/11 10:59
# @Author  : lt
# @Email   : lt@163.com
# @File    : xiansuochi_page.py
# @Software: PyCharm
from selenium.webdriver.common.by import By
from page.KHGL_page.Base_Page import BasePage
from selenium.webdriver.support.select import Select
from time import sleep

class KeHuChi_page(BasePage):
    # 定位筛选条件下拉框
    tiaojian_locator = (By.ID,'field')
    # 定位包含下拉框
    baohan_locator = (By.ID, 'condition')
    # 定位关键字输入框
    guanjianzi_locator = (By.ID, 'search')
    # 定位搜索按钮输入框
    sousuo_locator = (By.ID, 'dosearch')
    owerner_locator = (By.ID, 'owner_name')

    lianxiren_locator = (By.ID, 'd_content')

    ok_locator = (By.CSS_SELECTOR,
                  'body > div:nth-child(15) > div.ui-dialog-buttonpane.ui-widget-content.ui-helper-clearfix > div > button:nth-child(1) > span')

    ok2_locator = (By.CSS_SELECTOR,
                   'body > div:nth-child(11) > div.ui-dialog-buttonpane.ui-widget-content.ui-helper-clearfix > div > button:nth-child(1) > span')

    succeful_locator = (By.CSS_SELECTOR, 'body > div.container > div.alert.alert-success')


    # 输入框筛选条件
    def sousuo_tiaojian(self,tiaojian):
        Select(self.driver.find_element(*self.tiaojian_locator)).select_by_visible_text(tiaojian)
    # 输入筛选条件
    def sousuo_tiaojian2(self,tiaojian2):
        Select(self.driver.find_element(*self.baohan_locator)).select_by_visible_text(tiaojian2)
    # 输入关键字
    def guanjianzi_shuru(self,guanjianzi):
        self.driver.find_element(*self.guanjianzi_locator).send_keys(guanjianzi)
    # 点击搜索按钮
    def sousuo_button(self):
        self.driver.find_element(*self.sousuo_locator).click()
    #选择相应的线索查看按钮
    def xiansuo_caozuo(self,xiansuo,caozuo,index):
        tobdy = self.driver.find_element(By.CSS_SELECTOR, '#form1 > table > tbody')
        trs = tobdy.find_elements(By.TAG_NAME, 'tr')
        for i in trs:
            tds = i.find_elements(By.TAG_NAME, 'td')
            if tds[1].text == xiansuo:
                # 选择对应的线索点击查看
                tds[index].find_element(By.LINK_TEXT, caozuo).click()
                break

    # 点击负责人输入框
    def fuzeren(self):
        self.driver.find_element(*self.owerner_locator).click()
        sleep(3)
    #选择相应的负责人
    def fuzeren_shuru(self,name):
        lianxiren = self.driver.find_element(*self.lianxiren_locator)
        trss = lianxiren.find_elements(By.TAG_NAME, 'tr')
        for e in trss:
            tdss = e.find_elements(By.TAG_NAME, 'td')
            if tdss[1].text == name:
                # 选择负责人
                tdss[0].click()
    def fuzeren_queren(self):
        self.driver.find_element(*self.ok_locator).click()
        sleep(3)
    # 点击确定
    def queren_button(self):
        self.driver.find_element(*self.ok2_locator).click()
    #断言
    def fenpei_succeful(self):
        text = self.driver.find_element(*self.succeful_locator).text
        return text